package com.ln.property_control.controller;

import com.ln.property_control.pojo.*;
import com.ln.property_control.service.CheckPlanService;
import com.ln.property_control.service.ScrapService;
import com.ln.property_control.service.TransferService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

import java.util.List;

import javax.servlet.http.HttpSession;

/**
 * @author 刘念
 * @create 2021-07-07-18:34
 */

//跳转页面控制器，所有关于跳转页面放在这里面
@Controller
@RequestMapping("jump")
public class JumpController {

    @Autowired
    private TransferService transferService;
    @Autowired
    private ScrapService scrapService;
    @Autowired
    private CheckPlanService checkPlanService;

    //登录
    @RequestMapping("/login")
    public String login() {
        return "login/login";
    }

    //退出登录
    @RequestMapping("/clear")
    public String clear(HttpSession session) {
        session.removeAttribute("userInfo");
        return "login/login";
    }

    //资产管理首页面index
    @RequestMapping("/goIndex")
    public String goIndex() {
        return "index";
    }

    //资产管理
    @RequestMapping("/goAssetGu")
    public String goAssetGu() {
        return "asset/assetgu";
    }

    /*资产盘点模块*/
    @RequestMapping("/goCheck")
    public String gocheck() {
        return "asset/check/assetgu";
    }

    /*资产盘点展示*/
    @RequestMapping("/goShow")
    public String goShow() {
        return "asset/check/planShow";
    }

    //资产转移页面展示
    @RequestMapping("/goTransferIndex")
    public String goTransferIndex() {
        return "asset/transfer/index";
    }

    //资产调用申请页面展示
    @RequestMapping("/goclaimhistory")
    public String goclaimhistory() {
        return "asset/claim/history";
    }

    //资产调用申请页面展示
    @RequestMapping("/goclaimback")
    public String goclaimback() {
        return "asset/claim/back";
    }

    //资产调用页面展示
    @RequestMapping("/goclaimIndex")
    public String goclaimIndex() {
        return "asset/claim/index";
    }

    //资产添加页面展示
    @RequestMapping("/goclaimByAddAsset")
    public String goclaimByAddAsset() {
        return "asset/claim/addAsset";
    }

    //资产报废页面示
    @RequestMapping("/goScrapIndex")
    public String goScrapIndex() {
        return "asset/scrap/index";
    }

    //跳转申请报废表
    @RequestMapping("/gobuildScrap")
    public String gobuildScrap(Model model) {
        List<ScrapVo> FaulttypeList=  scrapService.selectFaulttype();
        model.addAttribute("FaulttypeList",FaulttypeList);
        return "asset/scrap/buildScrap";
    }

    //资产借用页面展示
    @RequestMapping("/goBorrowIndex")
    public String goBorrowIndex() {
        return "asset/borrow/index";
    }

    //资产归还页面展示
    @RequestMapping("/goRteurnIndex")
    public String gorteurnIndex() {
        return "asset/borrow/return";
    }

    //资产借用详情页面展示
    @RequestMapping("/goBorrowDetail")
    public String goBorrowDetail() {
        return "asset/borrow/detail";
    }

    //资产借用详情页面展示
    @RequestMapping("/goBorrowAddApply")
    public String goBorrowAddApply() {
        return "asset/borrow/apply";
    }

    //资产借用详情页面展示
    @RequestMapping("/goBorrowReturn")
    public String goBorrowReturn() {
        return "asset/borrow/return";
    }


    //跳转 查看资产报废详细表
    @RequestMapping("/goScrapDetail")
    public String goScrapDetail(String scrap_id, Model model,HttpSession session) {
        ScrapVo scrap1 = scrapService.selectScrapAll(scrap_id);
        Scrapphoto scrapphoto1 = scrapService.selectPhotoUrl(scrap_id);
        User userInfo = (User) session.getAttribute("userInfo");
        List<ScrapVo> FaulttypeList=  scrapService.selectFaulttype();
        List<ScrapVo> scrapVoList = scrapService.selectLIstScfa(scrap_id);
        model.addAttribute("FaulttypeList",FaulttypeList);
        model.addAttribute("FaulttypeId",scrapVoList);
        model.addAttribute("userInfo", userInfo);
        model.addAttribute("scrap", scrap1);
        model.addAttribute("scrapphoto", scrapphoto1);
        System.out.println(model);
        return "asset/scrap/scrapDetail";
    }

    //跳转维修成功维修记录表
    @RequestMapping("/gofoster")
    public String gofoster(String property_id,String property_name,String responsible,Model model){
        model.addAttribute("property_id",property_id);
        model.addAttribute("property_name",property_name);
        model.addAttribute("responsible",responsible);
        return "asset/scrap/foster";
    }



    //跳转资产转移查看
    @RequestMapping("/goTransferShow")
    public String selectByOrderNo(String transfer_order_no, Model model, HttpSession session) {
        TransferVo transfer = transferService.selectByOrderNo(transfer_order_no);
        User user1 = (User) session.getAttribute("userInfo");
        String type = user1.getType();
        List<PropertyAndTransferVo> propertyAndTransferVos = transferService.selectByOrderNOProperty(transfer_order_no);
        model.addAttribute("transfer", transfer);
        model.addAttribute("propertyAndTransferVos", propertyAndTransferVos);
        model.addAttribute("user", user1);
        return "asset/transfer/transferShow";
    }



    //申请资产转移
    @RequestMapping("/goTransferAdd")
    public String goTransferAdd() {
        return "asset/transfer/transferAdd";
    }

    //跳转盘点计划历史表
    @RequestMapping("gohistoryPlan")
    public String goHistoryPlan(){
        return "asset/check/historyPlan";
    }

    //跳转到总资产展示
    @RequestMapping("goSupProperty")
    public String goSupProperty(Model model){
        List<PropertyType> propertyTypeList = checkPlanService.findPropertyType();
        model.addAttribute("propertyTypeList",propertyTypeList);
        return "asset/check/supProperty";
    }

    //跳转个人所负责的计划
    @RequestMapping("goOwnCheckPlan")
    public String goOwnCheckPlan(Model model){
        List<Department> departmentList = checkPlanService.findDep();
        model.addAttribute("departmentList",departmentList);
        return "asset/check/ownCheckPlan";
    }
}
